package com.justech.eat.controller;

import com.justech.eat.controller.req.OrderDefaultSetReq;
import com.justech.eat.entity.OrderDefaultSet;
import com.justech.eat.service.OrderDefaultSetService;
import com.justech.eat.service.component.UserTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;

/**
 * @program: eat-service
 * @description: 默认报餐设置
 * @author: feifei.li
 * @create: 2020-06-04 11:44
 **/
@RestController
@Validated
@RequestMapping(value = "orderDefaultSet")
public class OrderDefaultSetController {

    @Autowired
    OrderDefaultSetService orderDefaultSetService;
    @Autowired
    UserTokenService uts;

    /**
     * 提交设置
     *
     * @param req
     * @return
     */
    @PostMapping
    public OrderDefaultSet set(@RequestBody @Valid OrderDefaultSetReq req, HttpServletRequest request) {
        return orderDefaultSetService.set(uts.getJobNumber(request), req.getLunch(), req.getDinner(), req.getMeal(), req.getNight());
    }

    /**
     * 查询一个用户的设置
     *
     * @return
     */
    @GetMapping
    public OrderDefaultSet get(HttpServletRequest request) {
        return orderDefaultSetService.getByJobNumber(uts.getJobNumber(request));
    }
}
